package com.sinodata.bsm.cicp.collector;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.ResultSetMetaData;

/**
 * 
 * <p>
 * Description: 
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-18 PM 5:36:25     liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class ResultSetMetaDataProxy implements InvocationHandler {

    ResultSetMetaData resultSetMetaData;

    public ResultSetMetaDataProxy(ResultSetMetaData resultSetMetaData) {
        this.resultSetMetaData = resultSetMetaData;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if ("getScale".equals(method.getName())) {
            int scale = resultSetMetaData.getScale((Integer) args[0]);
            return scale < 0 ? 0 : scale;
        } else if ("isCaseSensitive".equals(method.getName())) {
            try {
                return resultSetMetaData.isCaseSensitive((Integer) args[0]);
            } catch (Exception e) {
                return false;
            }
        }
        return method.invoke(resultSetMetaData, args);
    }

}
